<?php


namespace app\system\controller;

class App extends AdminBase
{
	public function getlist()
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$result = \app\system\service\AppService::getlist($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function getinfo($id)
	{
		$options = ["id" => $id];
		$result = \app\system\service\AppService::getinfo($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function add()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["name" => "require", "type" => "require", "avatar" => "require"], ["name.require" => "应用名称 不能为空", "type.require" => "应用类型 不能为空", "avatar.require" => "应用头像 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::add($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "添加成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function edit()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["id" => "require", "name" => "require", "avatar" => "require", "is_default" => "require"], ["id.require" => "id 不能为空", "name.require" => "name 不能为空", "avatar.require" => "avatar 不能为空", "is_default.require" => "is_default 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::edit($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "编辑成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function del()
	{
		$options = $this->request->post();
		$result = \app\system\service\AppService::del($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "删除成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_encryption_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_encryption_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_encryption_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_encryption_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_user_private_data_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_user_private_data_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_user_private_data_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require"], ["appid.require" => "appid 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_user_private_data_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_user_safe_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_user_safe_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_user_safe_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_user_safe_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_agent_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_agent_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_agent_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_agent_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_app_data()
	{
		$options = $this->request->get();
		$validate = \think\Validate::make(["appid" => "require"], ["appid.require" => "appid 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::get_app_data($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_member_app_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_member_app_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_member_app_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_member_app_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_buy_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_buy_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_buy_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_buy_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_buy_order_list()
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$result = \app\system\service\AppService::get_buy_order_list($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function get_card_app_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_card_app_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_card_app_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_card_app_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_auth_app_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_auth_app_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_auth_app_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_auth_app_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_classify_list()
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$result = \app\system\service\AppService::get_classify_list($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function get_classify_info($id)
	{
		$options = ["id" => $id];
		$result = \app\system\service\AppService::get_classify_info($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function add_classify()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["name" => "require", "sort" => "require"], ["name.require" => "应用名称 不能为空", "sort.require" => "排序号 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::add_classify($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "添加成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function edit_classify()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["name" => "require", "sort" => "require"], ["name.require" => "应用名称 不能为空", "sort.require" => "排序号 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::edit_classify($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "编辑成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function del_classify()
	{
		$options = $this->request->post();
		$result = \app\system\service\AppService::del_classify($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "删除成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_upload_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_upload_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_upload_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_upload_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_home_info($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_home_info($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_home_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_home_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_home_template_config_data($appid)
	{
		$options = $this->request->get();
		$validate = \think\Validate::make(["appid" => "require", "template" => "require"], ["appid.require" => "appid 不能为空", "template.require" => "template 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::get_home_template_config_data($options["appid"], $options["template"]);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function clear_home_config($appid)
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "template" => "require"], ["appid.require" => "appid 不能为空", "template.require" => "template 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::clear_home_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "清空成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_import_export_options()
	{
		$result = \app\system\service\AppService::get_import_export_options();
		$this->response(\app\system\model\Code::success, "获取成功", $result);
	}
	public function export_app_config_data()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require"], ["appid.require" => "appid 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::export_app_config_data($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "导出成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function import_app_config_data()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "configData" => "require"], ["appid.require" => "appid 不能为空", "configData.require" => "配置数据 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::import_app_config_data($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "导入成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_feedback_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_feedback_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_feedback_template()
	{
		$result = \app\system\service\AppService::get_feedback_template();
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_feedback_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_feedback_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_mail_config($appid)
	{
		$options = ["id" => $appid];
		$result = \app\system\service\AppService::get_mail_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function set_mail_config()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["appid" => "require", "config" => "require"], ["appid.require" => "appid 不能为空", "config.require" => "config 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\AppService::set_mail_config($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "设置成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function mail_send_test($appid, $email)
	{
		$options = ["id" => $appid, "email" => $email];
		$result = \app\system\service\AppService::mail_send_test($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "发送成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
}